<?php

namespace app\api\controller;

use think\Controller;

class Life extends Controller
{
    //游学体验
    public function life()
    {
        $life = model('common/Life')
            -> order('create_time','desc')
            -> field('id,img')
            -> limit(4)
            -> select();
        $cla = model('common/Classify')
            -> field('content')
            -> find();
        if ($life && $cla){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$life,'date'=>$cla]);
        } else {
            return json(['code'=>404,'请求失败']);
        }
    }

    //游学体验列表
    public function life_list()
    {
        $life = model('common/Life')
            -> order('create_time','desc')
            -> field('id,img,title')
            -> select();
        if ($life){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$life]);
        } else {
            return json(['code'=>404,'请求失败']);
        }
    }

    //游学体验详情
    public function life_content()
    {
        $life = model('common/Life')
            -> where('id',input('id'))
            -> field('title,num,author,create_time,content')
            -> find();
        $life -> setInc('num');
        if ($life){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$life]);
        } else {
            return json(['code'=>404,'请求失败']);
        }
    }
}
